<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\GrCoupon;
use App\Admin\show\goods;
use App\Models\GrGood;
use App\Models\GrGoodsType;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class Coupons extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new GrCoupon(), function (Grid $grid) {
            $grid->column('coupon_id', 'ID')->sortable();
            $grid->column('coupon_name', '优惠券名称');
            $grid->column('coupon_state', '状态')->radio(['上架', '下架']);
            $grid->column('coupon_min_price', '触发价格')->display(function ($e) {
                return $e . '元';
            });
            $grid->column('coupon_stock')->display(function ($e) {
                return $e . '张';
            });
            $grid->column('coupon_price')->display(function ($e) {
                return $e . '元';
            })->label();
            $grid->column('coupon_type')->radio(['满减券', '立减券']);
            $grid->column('coupon_application', '优惠券范围')->radio([1 => '通用券', 2 => '指定店铺可用', 3 => '指定商品']);
            $grid->column('coupon_astrict_type', '优惠券类型')->radio(['互斥', '共享']);
            $grid->column('coupon_effective_day', '有效期')->display(function ($e) {
                return $e . '天';
            })->label();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('coupon_name');
                $filter->equal('coupon_state')->select(['已上架', '已下架']);
                $filter->equal('coupon_type')->select(['满减券', '立减券']);
            });
        });
    }
}
